cmake_minimum_required(VERSION 2.8)
project(sylar)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLASGS} -rdynamic -O3 -g -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined")

# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include (cmake/utils.cmake)

include_directories(.)
include_directories(/usr/include)
link_directories(/usr/lib)
#123

set(LIB_SRC
    source/log.cpp
    source/util.cc
    source/config.cc
    source/thread.cc
    source/mutex.cc
    source/util.cc
    source/fiber.cc
    source/scheduler.cc
    source/iomanager.cc
    source/timer.cc
    source/hook.cc
    source/fd_manager.cc
    source/address.cc
    source/socket.cc
    source/bytearray.cc
    source/http/http.cc
    source/http/http_parser.cc
    source/tcp_server.cc
    source/stream.cc
    source/streams/socket_stream.cc
    source/http/http_session.cc
    source/http/servlet.cc
    source/http/http_server.cc
    #source/uri.cc
    source/streams/zlib_stream.cc
    source/http/http_connection.cc
    source/http/servlets/resource_servlet.cc
    source/http/servlets/img_servlet.cc
    source/daemon.cpp
    #source/http/servlets/config_servlet.cc
    #source/http/servlets/status_servlet.cc
    # source/rock/rock_protocol.cc
    # source/rock/rock_server.cc
    # source/rock/rock_stream.cc
    # source/module.cc
    )

ragelmaker(source/http/http11_parser.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/source/http)
ragelmaker(source/http/httpclient_parser.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/source/http)
ragelmaker(source/uri.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/source)
add_library(sylar SHARED ${LIB_SRC})
force_redefine_file_macro_for_sources(sylar)
#SET_TARGET_PROPERTIES (slyar_static PROPERTIES OUTPUT_NAME "sylar")


find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
    include_directories(${OPENSSL_INCLUDE_DIR})
endif()
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
    include_directories(${ZLIB_INCLUDE_DIR})
endif()

set(LIBS
    sylar
    yaml-cpp
    pthread
    dl
    ${ZLIB_LIBRARIES}
    ${OPENSSL_LIBRARIES}
)
add_executable(test tests/test.cc)
add_dependencies(test sylar)
force_redefine_file_macro_for_sources(test)
target_link_libraries (test ${LIBS})

add_executable(test_config tests/test_config.cc)
add_dependencies(test_config sylar)
force_redefine_file_macro_for_sources(test_config)
target_link_libraries (test_config ${LIBS})

add_executable(test_thread tests/test_thread.cc)
add_dependencies(test_thread sylar)
force_redefine_file_macro_for_sources(test_thread)
target_link_libraries (test_thread ${LIBS})

add_executable(test_util tests/test_util.cc)
add_dependencies(test_util sylar)
force_redefine_file_macro_for_sources(test_util)
target_link_libraries (test_util ${LIBS})

add_executable(test_fiber tests/test_fiber.cc)
add_dependencies(test_fiber sylar)
force_redefine_file_macro_for_sources(test_fiber)
target_link_libraries (test_fiber ${LIBS})

add_executable(test_scheduler tests/test_scheduler.cc)
add_dependencies(test_scheduler sylar)
force_redefine_file_macro_for_sources(test_scheduler)
target_link_libraries (test_scheduler ${LIBS})



add_executable(test_iomanager tests/test_iomanager.cc)
add_dependencies(test_iomanager sylar)
force_redefine_file_macro_for_sources(test_iomanager)
target_link_libraries (test_iomanager ${LIBS})

add_executable(test_hook tests/test_hook.cc)
add_dependencies(test_hook sylar)
force_redefine_file_macro_for_sources(test_hook)
target_link_libraries (test_hook ${LIBS})

add_executable(test_address tests/test_address.cc)
add_dependencies(test_address sylar)
force_redefine_file_macro_for_sources(test_address)
target_link_libraries (test_address ${LIBS})

add_executable(test_socket tests/test_socket.cc)
add_dependencies(test_socket sylar)
force_redefine_file_macro_for_sources(test_socket)
target_link_libraries (test_socket ${LIBS})


add_executable(test_bytearray tests/test_bytearray.cc)
add_dependencies(test_bytearray sylar)
force_redefine_file_macro_for_sources(test_bytearray)
target_link_libraries (test_bytearray ${LIBS})

add_executable(test_http tests/test_http.cc)
add_dependencies(test_http sylar)
force_redefine_file_macro_for_sources(test_http)
target_link_libraries (test_http ${LIBS})

add_executable(test_http_parser tests/test_http_parser.cc)
add_dependencies(test_http_parser sylar)
force_redefine_file_macro_for_sources(test_http_parser)
target_link_libraries (test_http_parser ${LIBS})

sylar_add_executable(test_tcp_server "tests/test_tcp_server.cc" sylar "${LIBS}")
sylar_add_executable(echo_server "examples/echo_server.cc" sylar "${LIBS}")
sylar_add_executable(test_http_server "tests/test_http_server.cc" sylar "${LIBS}")

sylar_add_executable(test_uri "tests/test_uri.cc" sylar "${LIBS}")
sylar_add_executable(test_http_connection "tests/test_http_connection.cc" sylar "${LIBS}")
sylar_add_executable(my_http_server "sample/my_http_server.cc" sylar "${LIBS}")
sylar_add_executable(resource_server "static_server/static_server.cc" sylar "${LIBS}")

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)